# # # # class Person(object):
# # # #     __limit = 0
# # # #
# # # #     def __init__(self, value):
# # # #         self.__value = value
# # # #         Person.__limit += 1
# # # #
# # # #     def show(self):
# # # #         print('self.__value:', self.__value)
# # # #         print('self.__limit:', self.__limit)
# # # #         print('Person.__limit:', Person.__limit)
# # # #
# # # #     @classmethod
# # # #     def classShowLimit(cls):
# # # #         print(cls.__limit)
# # # #
# # # #     @staticmethod
# # # #     def staticShowLimit():
# # # #         print(Person.__limit)
# # # #
# # # # p1 = Person(10)
# # # # p1.show()
# # # # p1.classShowLimit()
# # # # p1.staticShowLimit()
# # # #
# # # # p2 = Person(20)
# # # # p2.show()
# # # # p2.classShowLimit()
# # # # p2.staticShowLimit()
# # #
# # #
# # # # class Student(object):
# # # #     """控制该类只能创建3个对象，超过3个抛出异常"""
# # # #     limit = 0
# # # #     def __new__(cls, *args, **kwargs):
# # # #         if cls.limit >= 3:
# # # #             raise Exception("最多能创建3个对象")
# # # #         else:
# # # #             cls.limit += 1
# # # #             return object.__new__(cls)
# # # #     def __init__(self):
# # # #         print("limit: {0}".format(self.limit))
# # # #
# # # #
# # # # s1 = Student()
# # # # s2 = Student()
# # # # s3 = Student()
# # # # s4 = Student()
# # #
# # # # 演示：
# # # # 基类有构造方法，子类没有构造方法
# # # class Person(object):
# # #     def __init__(self,username,password):
# # #         self.__username = username
# # #         self.password = password
# # #         self.__getUsername()
# # #         self.getPassword()
# # #     def __getUsername(self):
# # #         print(self.__username)
# # #
# # #     def getPassword(self):
# # #         print(self.password)
# # #
# # # class Student(Person):
# # #     def __getUsername(self):
# # #         print(self.__username)
# # #
# # #     def getPassword(self):
# # #         print(self.password)
# # #
# # #
# # # s = Student("wangwu",'111111')
# # # print(s)
# #
# # # 下面代码完整描述了类的继承机制，深刻领会构造方法、私有方法、公有方法的继承原理
# # class A(object):
# #     def __privateFunc(self):
# #         print("A类的__privateFunc私有方法")
# #
# #     def publicFunc(self):
# #         print("A类的publicFunc公有方法")
# #
# #
# # class B(A):
# #     # B类没有构造方法
# #     def __privateFunc(self):
# #         print("B类的__privateFunc私有方法")
# #
# #     def publicFunc(self):
# #         print("B类的publicFunc公有方法")
# #
# #
# # a = A()
# # a.publicFunc()
#
# class A(object):
#     def __add__(self, other):
#         if isinstance(other, A):
#             return max(self.getValue()) + max(other.getValue())
#
#     def __init__(self, a, b):
#         if isinstance(a, (int, float)) and isinstance(b, (int, float)):
#             self.__a = a
#             self.__b = b
#         else:
#             raise Exception("请输入数值！")
#
#     def getValue(self):
#         return self.__a, self.__b
#
# a1 = A(1,20)
# a2 = A(30,4)
# print(a1+a2)
#

# 自定义数组
# class myArray(object):
#     """1、自定义一个数组类，实现数组元素的加减乘除运算
#        2、实现访问、修改、追加数组元素
#        3、重载成员测试运算符"""
#
#     def isNumber(self, n):
#         if not isinstance(n, (int, float, complex)):
#             print("您输入的 {0} 不是数值类型，请重新输入！".format(n))
#             return False
#         else:
#             return True
#
#     def __init__(self, *args):
#         if not args:
#             self.__value = []
#         else:
#             for arg in args:
#                 if not self.isNumber(arg):
#                     return
#             else:
#                 self.__value = list(args)
#
#     def __add__(self, n):
#         """
#         1、重载运算符+
#         对数组中每个元素与n相加，返回一个新数组
#         """
#         if self.isNumber(n) and len(self.__value) != 0:
#             self.__value = [i + n for i in self.__value]
#             return self.__value
#         elif len(self.__value) == 0:
#             raise Exception("数组的长度为0")
#         else:
#             raise Exception("n={0} 不是数字，请重新输入！".format(n))
#
#     def __sub__(self, n):
#         if self.isNumber(n) and len(self.__value) != 0:
#             self.__value = [i - n for i in self.__value]
#             return self.__value
#         elif len(self.__value) == 0:
#             raise Exception("数组的长度为0")
#         else:
#             raise Exception("n={0} 不是数字，请重新输入！")
#
#     def __mul__(self, n):
#         if self.isNumber(n) and len(self.__value) != 0:
#             self.__value = [i * n for i in self.__value]
#             return self.__value
#         elif len(self.__value) == 0:
#             raise Exception("数组的长度为0")
#         else:
#             raise Exception("n={0} 不是数字，请重新输入！")
#
#     def __truediv__(self, n):
#         if self.isNumber(n) and len(self.__value) != 0:
#             self.__value = [i / n for i in self.__value]
#             return self.__value
#         elif len(self.__value) == 0:
#             raise Exception("数组的长度为0")
#         else:
#             raise Exception("n={0} 不是数字，请重新输入！")
#
#     def append(self, n):
#         """追加元素"""
#         if self.isNumber(n):
#             self.__value.append(n)
#         else:
#             raise Exception("n={0} 不是数字，请重新输入！")
#
#     def getValue(self, index):
#         """根据索引index访问元素"""
#         if isinstance(index, int) and 0 <= index < len(self.__value):
#             return self.__value[index]
#         else:
#             raise Exception("index错误！")
#
#     def modifyValue(self, index, new_value):
#         """根据索引index修改元素"""
#         if isinstance(index, int) and 0 <= index < len(self.__value) and self.isNumber(new_value):
#             self.__value[index] = new_value
#         else:
#             raise Exception("index错误 or 输入的新值非数字！")
#
#     def __contains__(self, item):
#         """成员测试运算符"""
#         if self.isNumber(item):
#             if item not in self.__value:
#                 return False
#             else:
#                 return True
#         else:
#             raise Exception("输入值不是数字！")
#
#     def show(self):
#         return self.__value




if __name__ == "__main__":
    # m1 = myArray(1, 2, 3, 4, 5)
    # m1.modifyValue(0, 123)
    # print(4 in m1)
    var_list = list()
    for i in range(10):
        var = lambda i: i ** 2
        var_list.append(var)
    var2 = var_list[len(var_list)-1](2)
    print(var2)
